package cn.edu.tju.ldj.analytics.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.tju.ldj.analytics.Const;
import cn.edu.tju.ldj.analytics.Factory;

public class LoadContractListServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String goodId;
	private String alphaid;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			doMethod(request, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			doMethod(request, response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	private void doMethod(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		setGoodId(request.getParameter(Const.PARAM_FILE_SECTION_REQ_GCID));
		if(getGoodId() == null){
			setGoodId((String)request.getSession().getAttribute(Const.PARAM_FILE_SECTION_REQ_GCID));
		}
		setAlphaid(request.getParameter("alphaid"));
		System.out.println(getAlphaid());
		System.out.println(getGoodId());
		request.getSession().setAttribute(Const.PARAM_FILE_SECTION_REQ_GCID, getGoodId());
		request.getSession().setAttribute("alphaLst", Factory.utilParam.getAlphaLst(getAlphaid()));
		request.getSession().setAttribute("row", Factory.utilParam.getParam(Const.PARAM_FILE_SECTION_ROWS));
		request.getSession().setAttribute("contractList", Factory.servGood.getContractsByGoodId(getGoodId()));
		response.sendRedirect(Factory.utilParam.getParam(Const.PARAM_FILE_SECTION_PAGE_CTRCTLST));
	}

	public String getGoodId() {
		return goodId;
	}

	public void setGoodId(String goodId) {
		this.goodId = goodId;
	}
	
	public String getAlphaid() {
		return alphaid;
	}

	public void setAlphaid(String alphaid) {
		this.alphaid = alphaid;
	}
}
